//
//  LoginViewModel.m
//  ProjectForCustomer
//
//  Created by 钟游 on 2019/8/25.
//  Copyright © 2019年 钟游. All rights reserved.
//

#import "LoginViewModel.h"
#import "LoginService.h"
@implementation LoginViewModel
-(void)yd_initialize{
    [self.senderCodeCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.senderCodeSubject sendNext:x];
    }];
    [self.loginCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.loginSubject sendNext:x];
    }];
    [self.locationListCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.locationListSubject sendNext:x];
    }];
    [self.JpshuDeviceCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.JPushSubject sendNext:x];
    }];
    [self.nickNameCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.nickNameSubject sendNext:x];
    }];
    [self.personalCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.personalSubject sendNext:x];
    }];
    [self.thirdLoginCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.thirdLoginSubject sendNext:x];
    }];
    [self.bindPhoneCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.bindPhoneSubject sendNext:x];
    }];
    [self.tagListCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.tagListSubject sendNext:x];
    }];
    [self.directorListCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.directorListSubject sendNext:x];
    }];
    [self.actorListCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.actorListSubject sendNext:x];
    }];
    [self.moveTypeListCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.movetypeListSubject sendNext:x];
    }];
    [self.adCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.adSubject sendNext:x];
    }];
    [self.delegateCommand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        [self.delegateSubject sendNext:x];
    }];
}
#pragma mark command
-(RACCommand *)senderCodeCommand{
    if (!_senderCodeCommand) {
        _senderCodeCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            NSString * phoneNumber = input;
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceCheckCodeWithphoneNumber:phoneNumber Success:^(NSString * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _senderCodeCommand;
}
-(RACCommand *)loginCommand{
    if (!_loginCommand) {
        _loginCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceLoginWithInfo:input Success:^(NSDictionary * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _loginCommand;
}
-(RACCommand *)tagListCommand{
    if (!_tagListCommand) {
        _tagListCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceTagListWithInfo:input Success:^(TagListModel * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _tagListCommand;
}
-(RACCommand *)locationListCommand{
    if (!_locationListCommand) {
        _locationListCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceLocationListWithInfo:input Success:^(NSArray * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _locationListCommand;
}
-(RACCommand *)JpshuDeviceCommand{
    if (!_JpshuDeviceCommand) {
        _JpshuDeviceCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceBindJPushDeviceWithInfo:input Success:^(NSString * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _JpshuDeviceCommand;
}
-(RACCommand *)nickNameCommand{
    if (!_nickNameCommand) {
        _nickNameCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceNicknameWithInfo:input Success:^(NSString * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _nickNameCommand;
}
-(RACCommand *)personalCommand{
    if (!_personalCommand) {
        _personalCommand = [[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServicePersonalInfoWithInfo:input Success:^(NSString * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _personalCommand;
}
-(RACCommand *)thirdLoginCommand{
    if (!_thirdLoginCommand) {
        _thirdLoginCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceThirdLoginWithInfo:input Success:^(NSDictionary * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _thirdLoginCommand;
}
-(RACCommand *)bindPhoneCommand{
    if (!_bindPhoneCommand) {
        _bindPhoneCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceBindPhoneWithInfo:input Success:^(NSString * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _bindPhoneCommand;
}
-(RACCommand *)directorListCommand{
    if (!_directorListCommand) {
        _directorListCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceDirectorListWithInfo:input Success:^(NSString * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _directorListCommand;
}
-(RACCommand *)actorListCommand{
    if (!_actorListCommand) {
        _actorListCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceActorListWithInfo:input Success:^(NSString * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _actorListCommand;
}
-(RACCommand *)moveTypeListCommand{
    if (!_moveTypeListCommand) {
        _moveTypeListCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal  createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceMoveTypeListWithInfo:input Success:^(NSString * _Nonnull info) {
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _moveTypeListCommand;
}
-(RACCommand *)adCommand{
    if (!_adCommand) {
        _adCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceADListWithInfo:@{} Success:^(NSDictionary * _Nonnull info) {
                    [subscriber sendNext:info[@"imageUrl"]];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _adCommand;
}
-(RACCommand *)delegateCommand{
    if (!_delegateCommand) {
        _delegateCommand=[[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                [LoginService loginServiceDelegateSuccess:^(NSDictionary * _Nonnull info) {
                    self.license = info[@"license"];
                    self.policy = info[@"policy"];
                    [subscriber sendNext:info];
                    [subscriber sendCompleted];
                } failure:^(NSString * _Nonnull failStr) {
                    [subscriber sendNext:failStr];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
            
        }];
    }
    return _delegateCommand;
}
#pragma mark subject
-(RACSubject *)delegateSubject{
    if (!_delegateSubject) {
        _delegateSubject=[[RACSubject alloc]init];
    }
    return _delegateSubject;
}
-(RACSubject *)adSubject{
    if (!_adSubject) {
        _adSubject=[[RACSubject alloc]init];
    }
    return _adSubject;
}
-(RACSubject *)tagListSubject{
    if (!_tagListSubject) {
        _tagListSubject=[[RACSubject alloc]init];
    }
    return _tagListSubject;
}
-(RACSubject *)JPushSubject{
    if (!_JPushSubject) {
        _JPushSubject=[[RACSubject alloc]init];
    }
    return _JPushSubject;
}
-(RACSubject *)nickNameSubject{
    if (!_nickNameSubject) {
        _nickNameSubject=[[RACSubject alloc]init];
    }
    return _nickNameSubject;
}
-(RACSubject *)personalSubject{
    if (!_personalSubject) {
        _personalSubject=[[RACSubject alloc]init];
    }
    return _personalSubject;
}
-(RACSubject *)bindPhoneSubject{
    if (!_bindPhoneSubject) {
        _bindPhoneSubject=[[RACSubject alloc]init];
    }
    return _bindPhoneSubject;
}
-(RACSubject *)locationListSubject{
    if (!_locationListSubject) {
        _locationListSubject=[[RACSubject alloc]init];
    }
    return _locationListSubject;
}
-(RACSubject *)directorListSubject{
    if (!_directorListSubject) {
        _directorListSubject=[[RACSubject alloc]init];
    }
    return _directorListSubject;
}
-(RACSubject *)actorListSubject{
    if (!_actorListSubject) {
        _actorListSubject=[[RACSubject alloc]init];
    }
    return _actorListSubject;
}
-(RACSubject *)movetypeListSubject{
    if (!_movetypeListSubject) {
        _movetypeListSubject=[[RACSubject alloc]init];
    }
    return _movetypeListSubject;
}
-(RACSubject *)loginSubject{
    if (!_loginSubject) {
        _loginSubject=[[RACSubject alloc]init];
    }
    return _loginSubject;
}
-(RACSubject *)senderCodeSubject{
    if (!_senderCodeSubject) {
        _senderCodeSubject=[[RACSubject alloc]init];
    }
    return _senderCodeSubject;
}
-(RACSubject *)qqSubject{
    if (!_qqSubject) {
        _qqSubject=[[RACSubject alloc]init];
    }
    return _qqSubject;
}
-(RACSubject *)wbSubject{
    if (!_wbSubject) {
        _wbSubject=[[RACSubject alloc]init];
    }
    return _wbSubject;
}
-(RACSubject *)weiSubject{
    if (!_weiSubject) {
        _weiSubject=[[RACSubject alloc]init];
    }
    return _weiSubject;
}
-(RACSubject *)thirdLoginSubject{
    if (!_thirdLoginSubject) {
        _thirdLoginSubject=[[RACSubject alloc]init];
    }
    return _thirdLoginSubject;
}
@end
